<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" width="50%" destroy-on-close @closed="$emit('closed')" :close-on-click-modal="false">
        <el-container>
			<el-main class="nopadding">
				<scTable ref="table" :data="table" @select-all="selectAll" @selection-change="selectionChange"  stripe height="400" border>
					<el-table-column type="selection" width="50" align="center"></el-table-column>
                    <el-table-column label="姓名" prop="name" width="150"></el-table-column>
                    <el-table-column label="所属角色" prop="role_name" width="200"></el-table-column>
                    <el-table-column label="所属部门" prop="dept_name" width="200"></el-table-column>
                    <el-table-column label="所属岗位" prop="jobs_name" width="200"></el-table-column>
				</scTable>
			</el-main>
		</el-container>
		<template #footer>
			<el-button @click="visible = false">取 消</el-button>
			<el-button v-if="mode != 'show'" type="primary" :loading="isSaveing" @click="back">确 定</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			mode: "add",
			titleMap: {
				add: '选择指派人员',
			},
			visible: false,
			isSaveing: false,
            // apiObj: this.$API.system.admin.list,
            selection:[],
            table:[]
		}
	},
	mounted() {
        this.getHum()
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
        async getHum(){
            var res = await this.$API.all.getAdmin.get({is_page:0});
            this.table = res.data
        },
        submit(){
            this.visible = false
        },
        selectAll() {
			this.$message.error("只能单选！")
			this.$refs.table.clearSelection()
		},
        selectionChange(selection) {
            if(selection.length > 1){
				const del_row = selection.shift()
				this.$refs.table.toggleRowSelection(del_row,false) //设置这一行取消选中
			}
			this.selection = selection;
		},
        back(){
            this.$emit('success', this.selection)
            this.visible = false;
        },
	}
}
</script>

<style></style>
